﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NLUNZ.Business;

namespace NLUNZ
{
    public partial class News : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string newsId = Request.QueryString["id"];
            if(newsId != null)
            {
                int id;
                if(Int32.TryParse(newsId, out id))
                {
                    CompanyInfo news = Repository.GetNewsById(id);
                    if(news != null)
                    {
                        errorMessage.Visible = false;
                        NewsDataBind(news);
                    }
                    else
                    {
                        ShowErrorMessage();
                    }
                }
                else
                {
                    ShowErrorMessage();
                }
            }
        }

        private void ShowErrorMessage()
        {
            errorMessage.Visible = true;
        }

        private void NewsDataBind(CompanyInfo news)
        {
            newsDate.Text = "Date: " + news.CreateDate.ToString("yyyy-MM-dd");
            newsTitle.Text = news.Title;
            newsBody.Text = news.Content;
        }
    }
}